package day10;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * You are given the ages (in years) of allpeople of a country with 
 * at least 1 year of age.
 * You know that no individual in that country lives for 100 or more years. 
 * Now, you are given a very simple task of sorting all the ages in ascending order.
 * @author chenxiaokang
 *
 */

public class Ques1030QuickSort {
	
	public void quickSort(int arr[],int n){
		this.quickSort(arr,0,n-1);
	}
	
	private void quickSort(int arr[],int l,int r){
		if(l >= r)
			return;
		
		int p = partition(arr,l,r);
		this.quickSort(arr,l,p-1);
		this.quickSort(arr,p+1,r);
	}
	
	private int partition(int arr[],int l,int r){
		int v = arr[l];
		
		int j = l;
		for( int i = l + 1; i <= r ; i ++ ){
			if(arr[i] < v){
				this.swap(arr,++j,i);
			}
		}
		this.swap(arr, l, j);
		return j;
	}
	
	private void swap(int[] arr,int i,int j){
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}
	
		public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int n = 0;
			int[] scoreList;
			List<String> resultList = new ArrayList<String>();
			while(scan.hasNext()){
				n = scan.nextInt();
				if( n == 0){
					for(String str : resultList){
						System.out.println(str);
					}
					return;
				}
				scoreList = new int[n];
				for(int i = 0;i < n;i++){
					scoreList[i] = scan.nextInt();
				}
				new Ques1030QuickSort().quickSort(scoreList, n);
				String result = "";
				for(int i : scoreList){
					result += i+" ";
				}
				result = result.substring(0, result.length() - 1);
				resultList.add(result);
		}
	}
}
